package com.dayuanit.space.car;

import com.dayuanit.space.engine.EngineFactory;
import com.dayuanit.space.map.Map;
import com.dayuanit.space.engine.Engine;

public abstract class Car {

	public String name;

	private Map map;

	private EngineFactory engineFactory = new EngineFactory();

	public static final char w_order = 'w';
	public static final char s_order = 's';
	public static final char a_order = 'a';
	public static final char d_order = 'd';
	public static final char r_order = 'r';


	public static final int step = 1;

	public Car(String name) {
		this.name = name;
		this.map = new Map();
	}

	public Car(String name, int x, int y) {
		this.name = name;
		this.map = new Map(x, y);
	}


	public abstract void printOrder(char order);

	public abstract void printPoint(int x, int y);

	//模板设计模式
	public void move(char order) {
		//打印指令
		printOrder(order);

		Engine engine = engineFactory.create(order);
		engine.work(map, step);

		//打印坐标
		printPoint(map.getX(), map.getY());
	}


}